

public class RockPaperScissors {

	public RockPaperScissors(){
		
	}
	
	/**
	 * This method return the result of the game with as input an action of p1 and an action of p2
	 * 
	 * 
	 * @param p1
	 * @param p2
	 * @return
	 */

	public Result play(RPSEnum p1, RPSEnum p2){
		
		if(p1.equals(RPSEnum.SCISSORS) && p2.equals(RPSEnum.ROCK)){
			return Result.LOST;
		}
		
		else if (p1.equals(RPSEnum.ROCK) && p2.equals(RPSEnum.PAPER)){
			return Result.LOST;
		}
		else if (p1.equals(RPSEnum.PAPER) && p2.equals(RPSEnum.SCISSORS)){
			return Result.LOST;
		}
		
		else if (p1.equals(RPSEnum.ROCK) && p2.equals(RPSEnum.SCISSORS)){
			return Result.WIN;
		}
		else if (p1.equals(RPSEnum.PAPER) && p2.equals(RPSEnum.ROCK)){
			return Result.WIN;
		}
		else if (p1.equals(RPSEnum.SCISSORS) && p2.equals(RPSEnum.PAPER)){
			return Result.WIN;
		}
		
		else {
			return Result.TIE;
		}
		
	}
	
	/**
	 * This method return the return of the game of player p1 vs player p2 
	 * 
	 * @param p1
	 * @param p2
	 * @return
	 */
	
	
	public Result play(Player p1, Player p2){
		
		RPSEnum actionP1;
		RPSEnum actionP2;
		
		//we play all the steps of the game
		while((actionP1=p1.getNextMove())!=null && (actionP2=p2.getNextMove())!=null){

			//printRPSEnum(actionP1);
			//printRPSEnum(actionP2);

			if(play(actionP1, actionP2).equals(Result.WIN)){
				//System.out.println("WIN");
				p1.setScore(p1.getScore()+1);
			}
			else if(play(actionP1, actionP2).equals(Result.LOST)){
				//System.out.println("LOST");
				p2.setScore(p2.getScore()+1);
			}
			else {
				//System.out.println("TIE");
				p1.setScore(p1.getScore()+1);
				p2.setScore(p2.getScore()+1);
			}	

		}

		//we return the result
		if (p1.getScore()>p2.getScore()){
			return Result.WIN;
		}
		if (p1.getScore()<p2.getScore()){
			return Result.LOST;
		}
		else {
			return Result.TIE;
		}

	}
	
	
/*	public void printRPSEnum(RPSEnum e){
		
		if(e==RPSEnum.PAPER){
			System.out.println("Paper");
		}
		if(e==RPSEnum.ROCK){
			System.out.println("Rock");
		}
		if(e==RPSEnum.SCISSORS){
			System.out.println("Scissors");
		}
	}
*/	
}
